from tortoise import Tortoise
from app.core.config import settings
import logging

logger = logging.getLogger(__name__)

async def init_db(generate_schemas: bool = False) -> None:
    """初始化数据库连接"""
    await Tortoise.init(
        config=settings.get_tortoise_config(),
        use_tz=True
    )
    
    if generate_schemas:
        logger.info("Generating database schemas")
        await Tortoise.generate_schemas()

async def close_db() -> None:
    """关闭数据库连接"""
    await Tortoise.close_connections() 